from pymongo import MongoClient

client = MongoClient("localhost", 27017)
db = client["Pre_Data"]
collection = db["PlantsGene"]

for result in collection.find({"na_strand": {"$exists": 1}}):
    text = result["na_strand"]
    if text.startswith("plus"):
        collection.update_one({"_id": result["_id"]}, {"$set": {"na_strand": "plus"}})
        print(result["gene_track_geneid"] + " set plus.")
    elif text.startswith("minus"):
        collection.update_one({"_id": result["_id"]}, {"$set": {"na_strand": "minus"}})
        print(result["gene_track_geneid"] + " set minus.")

client.close()
